#include <stdio.h>
#include <stdlib.h>

void exchangeLeftandRight(int* array, int num) {
    printf("please input the elements of array:");
    for (int i = 0; i < num; i++)
        scanf("%d", &array[i]);
    int left = 0, right = num - 1;
    while (left < right) {
        // 左边找偶数，右边找奇数
        while (left < right && array[left] % 2 != 0)
            left++;
        while (right > left && array[right] % 2 == 0) 
            right--;

        int temp = array[right];
        array[right] = array[left];
        array[left] = temp;
        right--;
        left++;
    }

    printf("after exchanging the elements of array:");

    for (int i = 0; i < num; i++) 
        printf("%d ", array[i]);
    
    printf("\n");
}

int main() {
    int num = 0;
    printf("please input the numbers of array:");
    scanf("%d", &num);
    int* array = (int*)malloc(sizeof(int) * num);
    exchangeLeftandRight(array, num);
    free(array);
    return 0;
}
